/*
 * @Author: wuqingchun
 * @Date: 2024-09-23 19:56:01
 * @Description: 
 * @LastEditors: wuqingchun
 * @LastEditTime: 2024-09-24 20:32:36
 */

#include <functional>

#include "chat_errno.h"
#include "chat_config.h"
#include "chat_net.h"

CChatNet::CChatNet():
    m_refConfig(CChatConfig::GetInstance().GetCommonConfig()),
    m_objNetAddr(m_refConfig.usListenPort),
    m_objTcpServer(&m_objEVLoop, m_objNetAddr, m_strServerName)
{
    m_objTcpServer.setThreadNum(m_refConfig.usNetThreadNum);
    m_objTcpServer.setThreadInitCallback(std::bind(&CChatNet::__OnThreadInit, this, _1));
}

CChatNet::~CChatNet()
{
    
}

int32_t CChatNet::Start()
{
    m_objTcpServer.start();
    m_objEVLoop.loop();

    return 0;
}

void CChatNet::SetConnectCallback(const ConnectionCallback& refConnCB)
{
    m_objTcpServer.setConnectionCallback(refConnCB);
}

void CChatNet::setMessageCallback(const MessageCallback& refMsgCB)
{
    m_objTcpServer.setMessageCallback(refMsgCB);
}

void CChatNet::__OnThreadInit(EventLoop* pobjEVLoop)
{
    printf("work loop thread start\n");
}
